package com.itheima.hanoi;

import java.util.Scanner;

/**
 * @Author: Ethan Yankang
 * @Program: Interview
 * @Date: 2024-08-16 14:11
 **/
public class Hanoi {
    static int step=1;
    static int hanoi(int n,char from,char to,char via){
        if (n==1){
            System.out.println("移动步骤：a——>b");
            return 1;
        }else {
            int c1=hanoi(n-1,from,via,to);
            System.out.println((step)+":移动步骤\t"+from+"——>"+via+"借助了"+to);
            step++;
            int c2=hanoi(n-1,via,to,from);
            System.out.println((step)+":移动步骤\t"+via+"——>"+to+"借助了"+via);
            step++;
            return c1+c2+1;
        }
    }

    public static void main(String[] args) {
        System.out.println("请输入盘子总数：");
        Scanner scanner = new Scanner(System.in);
        int n=scanner.nextInt();
        int total= hanoi(n,'a','b','c');
        System.out.println(total+":移动步骤\ta——>c借助了b");
        System.out.println("移动"+n+"个盘子的总步骤为"+total+"次");
    }
}
